# coding=utf-8
'''
Created on 2018年4月6日

@author: lijie
'''
import os
from selenium import webdriver

class DriverAction:
    
    base_path = os.path.dirname(__file__)+'/../../drivers'
    def start_browser(self,browserType="0"):
        if browserType == "0":
            driver_exe = "/chromedriver2.37.exe"
            driver_path = self.base_path+driver_exe  # 椹卞姩鏂囦欢鍏ㄨ矾寰�
            self.dr = webdriver.Chrome(executable_path=driver_path)
        elif browserType == "1":
            driver_exe = "geckodriver.exe"
            driver_path = os.path.abspath(self.base_path + driver_exe)  # 椹卞姩鏂囦欢鍏ㄨ矾寰�
            self.dr = webdriver.Firefox(executable_path=driver_path)
        elif browserType == "2":
            driver_exe = "IEDriverServer.exe"
            driver_path = os.path.abspath(self.base_path + driver_exe)  # 椹卞姩鏂囦欢鍏ㄨ矾寰�
            self.dr = webdriver.Ie(executable_path=driver_path)
        else:
            driver_exe = "/chromedriver2.37.exe"
            driver_path = os.path.abspath(self.base_path + driver_exe)  # 椹卞姩鏂囦欢鍏ㄨ矾寰�
            self.dr = webdriver.Chrome(executable_path=driver_path)
        self.dr.get("bout:blank")
        self.dr.maximize_window()
        self.dr.implicitly_wait(30)
        return self.dr

Dr = DriverAction() # 绫诲崟渚嬪疄渚嬪寲
def driver():
    return Dr.start_browser()
